<?php

namespace app\common\business;

use app\common\lib\Arr;
use app\common\lib\Curl;
use app\common\lib\Num;
use app\common\lib\Status;
use app\common\lib\Str;
use app\common\lib\Time;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\Exception;
use think\facade\Cache;
use think\facade\Db;
use think\facade\Filesystem;

class Work
{

    public $model = null;

    public function __construct()
    {
        $this->model = new \app\common\model\mysql\Work();
    }

    /**
     * 获取分页列表
     * @throws Exception
     */
    public function getTableList($page=null,$limit=null,$param=[],$departmentId=null): array
    {
        $where=[];
        if(!empty($param['name'])){
            $where[]=['name','like','%'.$param['name'].'%'];
        }
        if(!empty($param['type'])){
            $where[]=['type','=',$param['type']];
        }
        if(!empty($param['valuation'])){
            $where[]=['valuation','=',$param['valuation']];
        }
        if(!empty($param['is_enterprise'])){
            $where[]=['is_enterprise','=',$param['is_enterprise']];
        }
        if(!empty($param['is_show'])){
            $where[]=['is_show','=',$param['is_show']];
        }
        if(!is_null($param['process_status']) || $param['process_status'] === 0){
            $where[]=['process_status','=',$param['process_status']];
        }
        if(!empty($param['department'])){
            if($param['department']==1&&!empty($departmentId)){
                $where[]=['department_id','=',$departmentId];
            }else if($param['department']==2){
                $where[]=['department_id','=',0];
            }
        }

        $data=$this->model->getTableList($where,$page,$limit);
        $data['list']=$this->resetTextList($data['list']);
        return $data;
    }

    /**
     * 人力资源公司抢活
     * @param $workId
     * @param $departmentId
     * @return true
     * @throws DataNotFoundException
     * @throws DbException
     * @throws Exception
     * @throws ModelNotFoundException
     */
    public function robWork($workId,$departmentId): bool
    {
        $department=(new Department())->getNormalById($departmentId);
        if(empty($department)){
            throw new Exception('公司不存在');
        }
        $this->model::startTrans();
        try {
            $work=$this->model->where(['id'=>$workId])->field(['department_id'])->lock(true)->find();
            if(empty($work)){
                throw new Exception('未查询到该零活');
            }
            if(!empty($work['department_id'])){
                throw new Exception('该零活已被抢走');
            }
            $this->model->where(['id'=>$workId])->update(['department_id'=>$departmentId]);
            $this->model->commit();
        }catch (\Exception $e){
            $this->model->rollback();
            throw new Exception($e->getMessage());
        }
        return true;
    }

    /**
     * 零活改价
     * @param $data
     * @param $departmentId
     * @return bool
     * @throws DataNotFoundException
     * @throws DbException
     * @throws Exception
     * @throws ModelNotFoundException
     */
    public function changePrice($data,$departmentId): bool
    {
        $work=$this->model->getNormalByField('id',$data['id'],'department_id,population,price');
        if($work['department_id']!=$departmentId){
            throw new Exception('您不可修改该零活');
        }

        if($data['is_show'] == 1) {
            //公开，更新公开时间同时更新过程状态
            $data['process_status'] = 1;
            $data['show_time'] = time();
        }
        $res = $this->model->saveData($data);
        if (!$res){
            throw new Exception('数据库内部异常');
        }

        //记录改价记录
        $recordModel = new \app\common\model\mysql\WorkCpRecord();
        $recordData = [
            'work_id'=>$data['id'],
            'department_id'=>$departmentId,
            'population'=>$data['population'],
            'population_origin'=>$work['population'],
            'price'=>$data['price'],
            'price_origin'=>$work['price'],
            'create_time'=>time()
        ];
        $res1 = $recordModel->saveData($recordData);
        if (!$res1){
            throw new Exception('数据库内部异常');
        }
        return true;
    }

    public function getListByWhere($where,$page,$limit,$field='*'){
        $where[] = ['status','=',config("status.mysql.table_normal")];
        if ($page!=0 && $limit !=0){
            $list = $this->model->getPageListByWhere($where,$page,$limit,$field);
        }else{
            $list = $this->model->getNormalListByWhere($where,$field);
        }
        if($list->isEmpty()){
            return [];
        }
        return $list->toArray();
    }

    public function getCountByWhere($where,$field='*'){
        $where[] = ['status','=',config("status.mysql.table_normal")];
        $list = $this->model->getNormalListByWhere($where,$field);

        return count($list);
    }

    public function getNormalById($id)
    {
        $data = $this->model->getById($id);
        if (!$data || $data->status != config("status.mysql.table_normal")) {
            return [];
        }
        return $data->toArray();
    }

    public function getNormalByField($field,$value): array
    {
        $data = $this->model->getNormalByField($field, $value);
        if (!$data || $data->status != config("status.mysql.table_normal")) {
            return [];
        }
        return $data->toArray();
    }

    public function getNormalByWhere($where,$field='*'): array
    {
        $data = $this->model->getNormalByWhere($where, $field);
        if (!$data || $data->status != config("status.mysql.table_normal")) {
            return [];
        }
        return $data->toArray();
    }

    public function handlerListByOrder($list,$order,$data){
        if(empty($list)){
            return [];
        }

        //$result = $list;
        $result = $this->distanceCalc($list,$data);

        $field = 'show_time';
        $orderBasis = 'desc';
        $order = $this->checkOrderBasis($order);//处理order
        switch ($order){
            case 2:
                //距离最近
                $field = 'distance_calc';
                $orderBasis = 'asc';
                break;
            case 3:
                //日期最近
                //由于条件中已加开工日期必须大于当前时间，故按开工日期与当前日期相比时间越小则为日期最近
                $field = 'start_time_diff';
                $orderBasis = 'asc';
                break;
            case 4:
                //工钱最高
                //目前暂时按单价排序
                $field = 'price';
                $orderBasis = 'desc';
                break;
            case 5:
                //信誉优先
                //查出人力资源单位信誉
                $depWhere = [
                    ['id','in',array_column($result,'department_id')]
                ];
                $departmentList = (new Department())->getListByWhere($depWhere,0,0,'id,name,employer_score,workers_score');
                $departmentArr = Arr::getKeyValueByTwoArray($departmentList,'employer_score,workers_score','id',1);
                foreach ($result as $k=>$v){
                    $result[$k]['score_total'] = $departmentArr[$v['department_id']] ?? 0;
                }

                $field = 'score_total';
                $orderBasis = 'desc';
                break;
        }

        $result = Arr::twoArraySortByField($result,$field,$orderBasis);
        return $result;
    }

    public function distanceCalc($list,$data){
        if(empty($list)){
            return [];
        }

        foreach ($list as $k=>$v){
            //计算距离
            $list[$k]['distance_calc'] = null; //单位公里
            if (!empty($data['latitude'])&&!empty($data['longitude'])){
                $list[$k]['distance_calc'] = Num::getDistance($data['latitude'],$data['longitude'],$v['latitude'],$v['longitude']);
            }

            //计算开工日期差
            $list[$k]['start_time_diff'] = $v['start_time'] - time();
        }
        return $list;
    }

    public function saveData($user_id, $data)
    {
        $userBis = new User();
        $user = $userBis->getNormalUserById($user_id);
        if (!$user) {
            throw new Exception("不存在该用户");
        }

        //必须实名认证，也能发活
        $autherizedFlag = $userBis->checkIsAutherized($user['autherized']);
        if (!$autherizedFlag){
            throw new Exception("只有通过实名认证的用户才能发活");
        }

        //发布前如果选择以企业身份发布，需要判断是否通过
        //企业身份/个人发布发布必须选择人力公司，人力公司再改价选择公开
        $isShow = false;
        if($data['is_enterprise'] == 1){
            $userAssoBis = new UserAssociation();
            $userAssociation = $userAssoBis->getNormalByField('user_id',$user_id);
            if (!$userAssociation) {
                throw new Exception("未关联企业，无法用企业身份发布");
            }

            if(!$userAssoBis->checkAuditYes($userAssociation['audit'])){
                throw new Exception("关联企业未通过审核，无法用企业身份发布");
            }

            /*if (empty($data['department_id'])){
                throw new Exception("以企业身份发布必须选择人资公司");
            }
            $departmentBis = new Department();
            $departmentInfo = $departmentBis->getNormalById($data['department_id']);
            if (!$departmentInfo) {
                throw new Exception("不存在该人资公司");
            }*/
        }else{
            //$data['department_id'] = 0;
            $isShow = true;
        }

        try {
            $isCreate = $this->checkAddOrUpdate($data['id']);//判断新增还是编辑
        }catch (\Exception $e) {
            throw new Exception($e->getMessage());
        }
        if ($isCreate == 1) {
            //新增
            $workData = $data;
            unset($workData['id']);
            $workData['user_id'] = $user_id;
            $workData['is_show'] = 2;//发布后不公开
            $workData['process_status'] = 0;//审核中
            $workData['start_time'] = strtotime($data['start_time']);
            $workData['status'] = config('status.mysql.table_normal');
            $workData['create_time'] = time();

            if ($isShow){
                //个人发布直接公开
                //参考管理后台公开方法，本类中changePrice
                /*$workData['is_show'] = 1;
                $workData['process_status'] = 1;
                $workData['show_time'] = time();*/
            }

            try {
                $res = $this->model->save($workData);
            } catch (\Exception $e) {
                throw new Exception("数据库内部异常");
            }
        }else{
            //更新
            //暂不可用
            $id = $data['id'];
            $work = $this->getNormalById($id);
            if (!$work) {
                throw new Exception("不存在该零活");
            }

            if($user_id != $work['user_id']){
                throw new Exception("只能修改自己发布的零活");
            }

            $workData = $data;
            unset($workData['id']);
            try {
                $res = $this->model->updateById($id,$workData);
            } catch (\Exception $e) {
                throw new Exception("数据库内部异常");
            }
        }
        return $res;
    }

    public function adminSaveData($department_id, $admin_id, $data)
    {
        if($department_id == 0){
            throw new Exception("只有人力资源公司可发活");
        }
        $departmentBis = new Department();
        $department = $departmentBis->getNormalById($department_id);
        if (!$department) {
            throw new Exception("不存在该人力资源公司");
        }

        try {
            $isCreate = $this->checkAddOrUpdate($data['id']);//判断新增还是编辑
        }catch (\Exception $e) {
            throw new Exception($e->getMessage());
        }
        if ($isCreate == 1) {
            //新增
            $workData = $data;
            unset($workData['id']);
            $workData['is_enterprise'] = 1; //企业发布？但是问题在于没有没有关联用户及企业，可能有问题，后续在转义时做判断
            $workData['department_id'] = $department_id;
            $workData['user_id'] = $admin_id;
            //$workData['user_id'] = 0; //=0且department_id!=0时判断为人力资源公司自己添加
            $workData['is_show'] = 2;//发布后不公开
            $workData['process_status'] = 0;//审核中，需要自己在零活改价中公开
            $workData['start_time'] = strtotime($data['start_time']);
            $workData['create_time'] = time();
            $workData['is_self'] = 1;

            try {
                $res = $this->model->save($workData);
            } catch (\Exception $e) {
                throw new Exception("数据库内部异常");
            }
        }else{
            //更新
            $id = $data['id'];
            $work = $this->getNormalById($id);
            if (!$work) {
                throw new Exception("不存在该零活");
            }
            if($work['is_show'] == 1){
                throw new Exception("公开后的零活信息不可修改");
            }
            if (in_array($work['process_status'],[1,2,3,4])){
                $process_status_text = config('work.process_status')[$info['process_status']] ?? '';
                throw new Exception('该零活'.$process_status_text.'，不可修改');
            }

            if($department_id != $work['department_id']){
                throw new Exception("只能修改自己发布的零活");
            }

            $workData = $data;
            $workData['start_time'] = strtotime($data['start_time']);
            unset($workData['id']);

            try {
                $res = $this->model->updateById($id,$workData);
            } catch (\Exception $e) {
                throw new Exception("数据库内部异常");
            }
        }
        return $res;
    }

    public function adminDeleteData($department_id,$id)
    {
        if($department_id == 0){
            throw new Exception("只有人力资源公司可删除");
        }
        $departmentBis = new Department();
        $department = $departmentBis->getNormalById($department_id);
        if (!$department) {
            throw new Exception("不存在该人力资源公司");
        }

        $work = $this->getNormalById($id);
        if (!$work) {
            throw new Exception("不存在该零活");
        }
        if($department_id != $work['department_id'] || !$this->isDepartmentSave($work)){
            throw new Exception("只能删除自己发布的零活");
        }
        if($work['is_show'] == 1){
            throw new Exception("公开后的零活信息不可删除");
        }
        if (in_array($work['process_status'],[1,2,3,4])){
            $process_status_text = config('work.process_status')[$info['process_status']] ?? '';
            throw new Exception('该零活'.$process_status_text.'，不可删除');
        }

        return $this->model->deleteById($id);
    }

    public function cancelData($user_id,$id)
    {
        $user = (new User())->getNormalUserById($user_id);
        if (!$user) {
            throw new Exception("不存在该用户");
        }

        $work = $this->getNormalById($id);
        if (!$work) {
            throw new Exception("不存在该零活");
        }

        $isCancel = $this->isCancel($work,$user_id);
        if ($isCancel['code'] == 0){
            throw new Exception($isCancel['msg']);
        }

        //更新
        $workData = ['process_status'=> 3];
        try {
            $res = $this->model->updateById($id,$workData);
        } catch (\Exception $e) {
            throw new Exception("数据库内部异常");
        }
        return $res;
    }

    /**
     * 更新开工日期、完工日期
     * @param $data
     * @param $departmentId
     * @return bool
     * @throws DataNotFoundException
     * @throws DbException
     * @throws Exception
     * @throws ModelNotFoundException
     */
    public function updateWorkTime($data,$departmentId): bool
    {
        $operate_type = 1;//延期
        in_array('end_time',array_keys($data)) && $operate_type = 2;//完工
        $work=$this->model->getNormalByField('id',$data['id'],'department_id,start_time,is_show,process_status');
        if($work['department_id']!=$departmentId){
            throw new Exception('您不可修改该零活');
        }

        $start_time_origin = $work['start_time'];
        if ($operate_type == 1){
            //延期条件 1.不管公开不公开 2.过程状态招工中、已过期的才能延期 3.延期时间不能晚于之前的开工日期
            $data['start_time'] = strtotime($data['start_time']);
            if (!in_array($work['process_status'],[1,4])){
                throw new Exception('该零活状态不符合延期条件');
            }
            if($data['start_time'] <= $start_time_origin){
                throw new Exception('延期日期必须晚于当前开工日期');
            }
        }else{
            //完工条件 1.必须公开 2.过程状态招工中的才能完工 3.完工时间不能晚于之前的开工日期
            $data['end_time'] = strtotime($data['end_time']);
            if (!in_array($work['is_show'],[1]) || !in_array($work['process_status'],[1])){
                throw new Exception('该零活状态不符合完工条件');
            }
            if($data['end_time'] <= $start_time_origin){
                throw new Exception('完工日期必须晚于当前开工日期');
            }

            $data['process_status'] = 2;//完工
        }
        return $this->model->saveData($data);
    }

    //判断新增或编辑
    public function checkAddOrUpdate($id){
        $isCreate = 1; //1新增 2编辑
        if ($id > 0){
            $info = self::getNormalById($id);
            if (empty($info)){throw new Exception("不存在该零活");}
            $isCreate = 2;
        }
        return $isCreate;
    }

    //排序依据是否有效，其他情况均重置为1
    public function checkOrderBasis($order){
        $basisArr = config('work.order');
        if (!in_array($order,array_keys($basisArr))) $order = 1;
        return $order;
    }

    //判断发过来的process_status是否有效
    public function checkProcessStatus($process_status){
        $flag = false;

        $basisArr = config('work.process_status');
        if (in_array($process_status,array_keys($basisArr))) $flag = true;
        return $flag;
    }

    //判断是否人力资源公司自己发活
    public function isDepartmentSave($info){
        $flag = false;

        if($info['is_self'] == 1){
            $flag = true;
        }
        return $flag;
    }

    //转义text
    public function resetTextList($list,$userId=null){
        if (empty($list)){
            return [];
        }

        $robBis= (new WorkRob());
        $collectBis= (new WorkCollect());
        $commentBis = new Comments();

        //根据指定字段判断userid是后台管理员还是小程序用户
        $userIdArr = [];
        $adminIdArr = [];
        foreach ($list as $k=>$v){
            if ($this->isDepartmentSave($v)){
                $adminIdArr[] = $v['user_id'];
            }else{
                $userIdArr[] = $v['user_id'];
            }
        }

        //人力资源单位
        $depWhere = [
            ['id','in',array_column($list,'department_id')]
        ];
        $departmentList = (new Department())->getListByWhere($depWhere,0,0,'id,name,logo,address,employer_score,workers_score');
        $departmentArr = Arr::getKeyValueByTwoArray($departmentList,'','id',2);

        //关联企业，需要取小程序用户idarr
        $enterprise=(new UserAssociation())->getListByWhere([['user_id','in',$userIdArr]],0,0,'id,name,user_id');
        $enterpriseArr=Arr::getKeyValueByTwoArray($enterprise,'','user_id',2);

        //派遣工人列表（只有自己发的活显示）
        $robWhere = [
            ['work_id','in',array_column($list,'id')],
            ['is_employed','=',1] //显示已派遣的
        ];
        $robList = $robBis->getListByWhere($robWhere,0,0,'id,work_id,user_id,is_employed');
        $robUserId = !empty($robList) ? array_column($robList,'user_id') : [];

        //所有小程序用户列表
        $userIdArrWithRobUser = array_merge_recursive($robUserId,$userIdArr);
        $userWhere=[
            ['id','in',$userIdArrWithRobUser]
        ];
        $userList=(new User())->getListByWhere($userWhere,0,0,'id,name,sex,avatar,phone_number');
        $userArr = Arr::getKeyValueByTwoArray($userList,'','id',2);

        //所有管理员列表
        $adminWhere = [
            ['id','in',$adminIdArr]
        ];
        $adminList = (new AdminUser())->getListByWhere($adminWhere,0,0,'id,real_name as name,phone as phone_number');
        $adminArr = Arr::getKeyValueByTwoArray($adminList,'','id',2);

        //接上派遣工人列表
        $robArr = [];
        if (!empty($robList)){
            foreach ($robList as $k=>$v){
                if (isset($userArr[$v['user_id']])){
                    $userArr[$v['user_id']]['total_score'] = $commentBis->handlerCalcTotalScore(2,$v['user_id']);
                    $robList[$k]['user'] = $userArr[$v['user_id']];
                }
            }
            foreach ($robList as $k=>$v){
                $robArr[$v['work_id']][] = $v;
            }
        }

        //评价
        $commentsArr = [];
        if (!is_null($userId)){
            //我发出的评价
            $mapComments = [
                ['type','in',[2,3]],
                ['user_id','=',$userId]
            ];
            $commentsList = $commentBis->getListByWhere($mapComments,0,0,'id,type,user_id,work_id,associated_id');
            if (!empty($commentsList)){
                foreach ($commentsList as $k=>$v){
                    $commentsArr[$v['type'].'-'.$v['user_id'].'-'.$v['work_id'].'-'.$v['associated_id']] = 1;//我 对 这个工作这个人力资源公司 的评价
                }
            }
        }

        //
        $workType=(new WorkType())->getChildDictionaries();

        foreach ($list as $k=>$v){
            $list[$k]['duration'] = floatval($v['duration']);//5.00 5.01 5.10 => 5 5.01 5.1
            $list[$k]['show_time_text'] =isset($v['show_time'])?Time::formatTheTime($v['show_time'],'i'):'';
            $list[$k]['start_time_text'] =isset($v['start_time'])?Time::formatTheTime($v['start_time'],'i'):'';
            $list[$k]['end_time_text'] = isset($v['end_time'])?Time::formatTheTime($v['end_time'],'i'):'';
            $list[$k]['distance_calc'] = isset($v['distance_calc'])/*&&!empty($v['distance_calc'])*/ ? $this->getDistanceText($v['distance_calc']) : '暂无';
            $unit=$this->getUnitText($v['valuation']);
            $list[$k]['price_text'] ='元/'.$unit;
            $list[$k]['unit_text'] =$unit;
            $list[$k]['process_status_text'] = $this->getProcessStatusText($v['process_status']);

            $list[$k]['department'] = $departmentArr[$v['department_id']] ?? null;
            if($this->isDepartmentSave($v)){
                //人力资源自己发布
                $list[$k]['user'] = $adminArr[$v['user_id']] ?? null;
                if(!empty($list[$k]['department'])){
                    $list[$k]['enterprise']= $list[$k]['department'];
                }
            }else{
                //用工方发布
                $list[$k]['user'] = $userArr[$v['user_id']] ?? null;
                if(!empty($list[$k]['user'])){
                    $list[$k]['enterprise']=$enterpriseArr[$list[$k]['user']['id']]??null;
                }
            }

            if(isset($v['attachment'])){
                $list[$k]['attachment']=explode(',',$v['attachment']);
            }
            if(isset($v['type'])){
                $list[$k]['type_text']=isset($workType[$v['type']])?$workType[$v['type']]['name']:'';
            }
            if($userId){
                //$userId为当前登录小程序用户ID
                if($userId == $v['user_id']){
                    //我发的活
                    $list[$k]['is_comments'] = 0;//默认未评价

                    //判断能否取消，没有被人力资源单位抢活可取消
                    $list[$k]['is_cancel']=0;
                    if($v['process_status']!=3){
                        $isCancelRes = $this->isCancel($v,$userId);
                        $list[$k]['is_cancel'] = $isCancelRes['code'];
                    }

                    //同时显示后台人力资源公司派遣工人列表
                    $list[$k]['work_rob'] = $robArr[$v['id']] ?? [];

                    //同时判断是否已评价
                    //$list[$k]['is_comments'] = $commentsArr['2-'.$v['user_id'].'-'.$v['id'].'-'.$v['department_id']] ?? 0;
                    $list[$k]['is_comments'] = $commentsArr['2-'.$userId.'-'.$v['id'].'-'.$v['department_id']] ?? 0;

                    $list[$k]['is_rob']= 0; //我发的活必然没有抢活按钮
                }else{
                    //我接的活
                    $list[$k]['is_comments'] = -1;//默认不显示评价

                    $robInfo = $robBis->isRob($userId,$v['id']);
                    $list[$k]['is_rob']= $robInfo ? 1 : 0;
                    $list[$k]['work_rob_id']=$robInfo['id'] ?? 0;
                    $list[$k]['is_collect']=$collectBis->isCollect($userId,$v['id']);

                    //展示评价按钮前先要判断是否被选择派遣
                    //同时判断是否已评价
                    if ($robInfo){
                        if ($robInfo['is_employed'] == 1){
                            //$list[$k]['is_comments'] = $commentsArr['3-'.$v['user_id'].'-'.$v['id'].'-'.$v['department_id']] ?? 0;
                            $list[$k]['is_comments'] = $commentsArr['3-'.$userId.'-'.$v['id'].'-'.$v['department_id']] ?? 0;
                        }
                    }
                }
            }
        }
        return $list;
    }

    // 前端零活详情中重置用工方联系方式为人力资源公司联系方式，防止跑单
    public function resetInfo($info){
        if (empty($info[0])){
           return [];
        }

        //先判断为用工方发活
        if (!$this->isDepartmentSave($info[0])){
            $adminUserList = (new AdminUser())->getListByWhere([['department_id','=',$info[0]['department_id']]],0,0,'id,real_name as name,phone as phone_number');
            if (isset($adminUserList[0])){
                $info[0]['user'] = $adminUserList[0];
            }
        }

        return $info;
    }

    //距离text
    public function getDistanceText($value){
        return '距您'.number_format($value,2).'km';
    }

    //计价方式单位text
    public function getUnitText($valuation){
        return config('work.valuation_unit')[$valuation] ?? '-';
    }

    //过程状态text
    public function getProcessStatusText($process_status){
        $text = config('work.process_status')[$process_status] ?? '-';
        return $text;
    }

    /**
     * 根据ID查询详情
     * @param $id
     * @return array|mixed
     * @throws DataNotFoundException
     * @throws DbException
     * @throws Exception
     * @throws ModelNotFoundException
     */
    public function getDetailById($id)
    {
        $data = $this->model->getById($id);
        if (!$data || $data->status != config("status.mysql.table_normal")) {
            throw new Exception('数据不存在');
        }
        return $this->resetTextList([$data->toArray()])[0];
    }

    /**
     * 判断零活是否可以取消
     * @param $info //零活info
     * @param $userId //当前登录用户ID
     * @return array
     */
    public function isCancel($info,$userId){
        $data = [
            'code'=>0,
            'msg'=>'不可取消'
        ];

        if ($info['user_id'] != $userId){
           $data['msg'] = '只能取消自己发布的零活';
           return $data;
        }

        if ($info['department_id'] != 0){
            $data['msg'] = '该零活已关联人力资源公司，不可取消';
            return $data;
        }

        /*if ($info['is_show'] == 1){
            $data['msg'] = '该零活已公开，不可取消';
            return $data;
        }

        if (in_array($info['process_status'],[1,2,3,4])){
            $process_status_text = config('work.process_status')[$info['process_status']] ?? '';
            $data['msg'] = '该零活'.$process_status_text.'，不可取消';
            return $data;
        }*/

        $data['code'] = 1;
        $data['msg'] = 'OK';
        return $data;
    }
}
